<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class OAPosition extends Model
{
    protected $table = 'position';
    const ROLE_ADMIN = 95;

    //获取所有的职位
    public static function getAllPosition(): array
    {

        //$isSetAdmin = self::isSetAdmin();

        return self::query()
                    ->where('status',1)
//                    ->when($isSetAdmin,function($q) {
//                        return $q->where('id','<>',self::ROLE_ADMIN);
//                    })
                    ->select(['id','title'])
                    ->get()
                    ->toArray();
    }

    //超级管理员是否设置
    public static function isSetAdmin()
    {
        DB::enableQueryLog();
         return OAStaff::query()
           ->where('position_id',95)
           ->orWhereRaw("FIND_IN_SET ('95',roleid)")
           ->exists();
         //dd(DB::getQueryLog());
    }

}
